package com.lzy.concertticket.controller;

import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzy.concertticket.aop.log.ApiLog;
import com.lzy.concertticket.model.R;
import com.lzy.concertticket.model.entity.ArtistEntity;
import com.lzy.concertticket.model.req.ArtistReq;
import com.lzy.concertticket.model.vo.ArtistVo;
import com.lzy.concertticket.service.ArtistService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/artist")
public class ArtistController {
    @Autowired
    private ArtistService artistService;

    @ApiLog(title = "录入明星信息")
    @PostMapping
    public R addArtist(@RequestBody ArtistReq artistReq) {
        boolean r = artistService.addArtist(artistReq);
        return R.success(r);
    }

    @ApiLog(title = "查询明星信息")
    @GetMapping("/info")
    public R getArtistInfo(ArtistReq artistReq) {
        ArtistVo artistInfo = artistService.getArtistInfo(artistReq);
        return R.success(artistInfo);
    }

    //  分页查询
    @ApiLog(title = "分页查询明星信息")
    @GetMapping("/page")
    public R getArtistPage(ArtistReq artistReq) {
        Page<ArtistVo> page = artistService.getArtistPage(artistReq);
        return R.success(page);
    }

    //  修改明星信息
    @ApiLog(title = "修改明星信息")
    @PutMapping
    public R updateArtist(@RequestBody ArtistReq artistReq) {
        artistService.updateArtist(artistReq);
        return R.success();
    }

    //  导出明星信息为excel
    @ApiLog(title = "导出明星信息为excel")
    @GetMapping("/export")
    public void export() throws IOException {
        artistService.export();
    }

    //  删除明星
    @ApiLog(title = "删除明星")
    @DeleteMapping("/{artistId}")
    public R deleteArtist(@PathVariable Long artistId) {
        artistService.deleteArtist(artistId);
        return R.success();
    }

}
